package cn.test;

/**
 * @ClassName AverageCapitalPlusInterest
 * @Description TODO
 * @Author 郑万富
 * @Date 2020/11/9 10:33
 * @Version 1.0
 */

/**
 * 等额本息类
 * 等额本金是指一种贷款的还款方式，是在还款期内把贷款数总额等分，每月偿还同等数额的本金和剩余贷款在该月所产生的利息，
 * 这样由于每月的还款本金额固定，而利息越来越少，借款人起初还款压力较大，但是随时间的推移每月还款数也越来越少。
 * 变量名：贷款本金：loanMoney; 年利率：yearRate; 还款总月数：totalMonth;
 */
/*public class AverageCapitalPlusInterest {
    private double loanMoney;
    private double yearRate;
    private double totalMonth;

}*/


import java.util.Date;
import java.util.Scanner;

class Loan{
    private double yearRate;               //一笔贷款的年利率
    private int numberOfYears;                       //一笔贷款的贷款年限
    private double loanMoney;                        //一笔贷款的贷款额
    private Date loanDate;                            //贷款创建的日期
    Loan(){
    }
    public Loan(double yearRate, int numberOfYears, double loanMoney, Date loanDate) {
        loanDate = new Date();
        this.yearRate = yearRate;
        this.numberOfYears = numberOfYears;
        this.loanMoney = loanMoney;
        this.loanDate = loanDate;
    }                                                    //以用户指定值创建一笔贷款的构造方法
    public void Loan(){
        this.Loan();
        this.yearRate = 3;
        this.numberOfYears = 10;
        this.loanMoney = 806.0;
        loanDate = new Date();
    }                                                   //以默认值创建一笔贷款的无参构造方法
    public Date getLoanDate() {
        return loanDate;
    }                                                   //loanDate访问器
    public double getYearRate() {
        return yearRate;
    }                                                   //yearRate访问器
    public void setYearRate(double yearRate) {
        this.yearRate = yearRate;
    }                                                  //yearRate修改器
    public int getNumberOfYears() {
        return numberOfYears;
    }                                                  //numberOfYears访问器
    public void setNumberOfYears(int numberOfYears) {
        this.numberOfYears = numberOfYears;
    }                                                  //numberOfYears修改器
    public double getLoanMoney() {
        return loanMoney;
    }                                                  //loanMoney访问器
    public void setLoanMoney(double loanMoney) {
        this.loanMoney = loanMoney;
    }                                                 //loanMoney修改器
    public double getMonthlyPayment() {
        return loanMoney * (yearRate/1200) / (1 - Math.pow(1 / (1 + yearRate/1200), (numberOfYears * 12)));
    }                                                //计算并返回月还款额
    public double getTotalPayment() {
        return (loanMoney * (yearRate/1200) / (1 - Math.pow(1 / (1 + yearRate/1200), (numberOfYears * 12)))) * numberOfYears * 12;
    }                                                //计算并返回总还款额
}

public class AverageCapitalPlusInterest {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Loan m = new Loan();                     //创建一个贷款对象
        System.out.print("请输入贷款年利率：");
        m.setYearRate(input.nextDouble());
        System.out.print("请输入贷款年限：");
        m.setNumberOfYears(input.nextInt());
        System.out.print("请输入贷款金额：");
        m.setLoanMoney(input.nextDouble());
        System.out.println("贷款年利率是：" + m.getYearRate());
        System.out.println("贷款总额是：" + m.getLoanMoney());
        System.out.println("贷款年限是：" + m.getNumberOfYears());
        System.out.println("月还款额是：" + m.getMonthlyPayment());
        System.out.println("还款总额是：" + m.getTotalPayment());

    }
}


